package com.kitty.game.rank.model.monitor;

import com.kitty.game.role.model.Role;
import com.kitty.listener.EventDispatcher;
import com.kitty.listener.EventType;
import com.kitty.listener.event.*;

/**角色属性监听*/
public class RoleAttribMonitor {
    private Role role;

    private int phyPower;//物理伤害
    private int magPower;//法术伤害
    private int defense;//防御
    private int speed;//速度
    private int zhanli;


    public RoleAttribMonitor(Role role) {
        this.role = role;

        /**先存储当前值*/
        this.phyPower = (role.getMaxPhyPower());
        this.magPower = (role.getMaxMagPower());
        this.defense = (role.getMaxDefense());
        this.speed = (role.getMaxSpeed());
        this.zhanli = (role.getMaxPhyPower()+ role.getMaxLife()+role.getMaxDefense()+role.getMagPower()+role.getMaxMana()+ role.getMaxSpeed())*2;
    }

    /**监听结束*/
    public void end() {
        /**对比当前值与之前值是否有差异，有差异时产生对应的改变事件*/
        boolean falg = false;
        int currentPhyPower = role.getMaxPhyPower();
        if (currentPhyPower != phyPower) {
            falg = true;
            /** 产生一个物理伤害改变事件 */
            EventDispatcher.getInstance().fireEvent(new PhyPowerChangeEvent(EventType.PHY_POWER_CHANGE, role, currentPhyPower));
        }
        int currentMagPower =role.getMaxMagPower();
        if (currentMagPower != magPower) {
            falg = true;
            /** 产生一个法术伤害改变事件 */
            EventDispatcher.getInstance().fireEvent(new MagPowerChangeEvent(EventType.MAG_POWER_CHANGE, role, currentMagPower));
        }
        int currentDefense = role.getMaxDefense();
        if (currentDefense != defense) {
            falg = true;
            /** 产生一个防御改变事件 */
            EventDispatcher.getInstance().fireEvent(new DefenseChangeEvent(EventType.DEFENSE_CHANGE, role, currentDefense));
        }
        int currentSpeed = role.getMaxSpeed();
        if (currentSpeed != speed) {
            falg = true;
            /** 产生一个速度改变事件 */
            EventDispatcher.getInstance().fireEvent(new SpeedChangeEvent(EventType.SPEED_CHANGE, role, currentSpeed));
        }
        if(falg){
            int zhanli = (role.getMaxPhyPower()+ role.getMaxLife()+role.getMaxDefense()+role.getMagPower()+role.getMaxMana()+ role.getMaxSpeed())*2;
            /** 产生一个战力改变事件 */
            EventDispatcher.getInstance().fireEvent(new ZhanLiChangeEvent(EventType.ZHAN_LI_CHANGE, role, zhanli));
        }
    }
}
